package com.hmsproject.dummydata;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.hmsproject.datastructures.event.Event;
import com.hmsproject.datastructures.event.EventSchedule;
import com.hmsproject.search.managedbean.LocationAutoCompleteText;

public class EventDummyData {

	private SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd");
	public Map<String, List<Event>> eventMap = new HashMap<>();

	public void init() {
		LocationAutoCompleteText text = new LocationAutoCompleteText();
		List<String> strings = text.completeText("a");

		this.addEventsToLocationOneMap(strings.get(0));
		this.addEventsToLocationTwoMap(strings.get(1));
		this.addEventsToLocationThreeMap(strings.get(2));
		this.addEventsToLocationFourMap(strings.get(3));
		this.addEventsToLocationFiveMap(strings.get(4));
		this.addEventsToLocationSixMap(strings.get(5));
	}

	private void addEventsToLocationOneMap(String locationName) {
		List<Event> events = new ArrayList<Event>();
		events.add(this.createEventsWithLatLong("49ers", locationName, "2015-1-25",
				"2015-1-30", "49ers.png",37.43183, -121.89535));
		events.add(this.createEvents("Diwali", locationName, "2015-1-26",
				"2015-1-28", "firework.png"));
		events.add(this.createEvents("Concert", locationName, "2015-1-27",
				"2015-1-29", "music.png"));
		this.eventMap.put(locationName, events);
	}



	private void addEventsToLocationTwoMap(String locationName) {
		List<Event> events = new ArrayList<Event>();
		events.add(this.createEvents("Baseball", locationName, "2015-2-3",
				"2015-2-6", "baseball.png"));
		events.add(this.createEvents("Boxing", locationName, "2015-2-3",
				"2015-2-4", "boxing.png"));
		events.add(this.createEvents("Golf", locationName, "2015-2-6",
				"2015-2-8", "golf.png"));
		this.eventMap.put(locationName, events);
	}

	private void addEventsToLocationThreeMap(String locationName) {
		List<Event> events = new ArrayList<Event>();
		events.add(this.createEvents("Wedding", locationName, "2015-2-10",
				"2015-2-13", "wedding.jpg"));
		events.add(this.createEvents("Tennis", locationName, "2015-2-10",
				"2015-2-12", "tennis.png"));
		events.add(this.createEvents("Basketball", locationName, "2015-2-13",
				"2015-2-17", "basketball.png"));
		this.eventMap.put(locationName, events);
	}

	private void addEventsToLocationFourMap(String locationName) {
		List<Event> events = new ArrayList<Event>();
		events.add(this.createEvents("Rugby", locationName, "2015-2-14",
				"2015-2-17", "rugby.png"));
		events.add(this.createEvents("Skating", locationName, "2015-2-15",
				"2015-2-17", "skating.png"));
		events.add(this.createEvents("Football", locationName, "2015-2-16",
				"2015-2-18", "football.png"));
		this.eventMap.put(locationName, events);
	}

	private void addEventsToLocationFiveMap(String locationName) {
		List<Event> events = new ArrayList<Event>();
		events.add(this.createEvents("Iceskating", locationName, "2015-2-19",
				"2015-2-22", "iceskating.png"));
		events.add(this.createEvents("Cricket", locationName, "2015-2-20",
				"2015-2-21", "cricket.png"));
		events.add(this.createEvents("Music", locationName, "2015-2-20",
				"2015-2-24", "music.png"));
		this.eventMap.put(locationName, events);
	}

	private void addEventsToLocationSixMap(String locationName) {
		List<Event> events = new ArrayList<Event>();
		events.add(this.createEvents("49ers", locationName, "2015-2-25",
				"2015-2-30", "49ers.png"));
		events.add(this.createEvents("Billiards", locationName, "2015-2-28",
				"2015-2-30", "billiards.jpg"));
		events.add(this.createEvents("Bikerace", locationName, "2015-2-27",
				"2015-2-30", "bikerace.png"));
		this.eventMap.put(locationName, events);
	}

	private Event createEvents(String eventName, String eventLocation,
			String fromDate, String toDate, String imageName) {
		EventSchedule eventSchedule = null;
		try {
			eventSchedule = new EventSchedule(ft.parse(fromDate),
					ft.parse(toDate));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return new Event(eventName, eventLocation, eventSchedule, imageName);
	}
	
	private Event createEventsWithLatLong(String eventName, String eventLocation,
			String fromDate, String toDate, String imageName,Double latitude,Double longtitude) {
		EventSchedule eventSchedule = null;
		try {
			eventSchedule = new EventSchedule(ft.parse(fromDate),
					ft.parse(toDate));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return new Event(eventName, eventLocation, eventSchedule, imageName,latitude,longtitude);
	}
}
